package org.zizi.db.plan.reader;

import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import org.zizi.db.column.ColumnReader;
import org.zizi.db.plan.ResultReader;

public class ListResultReader<T> implements ResultReader<T>
{
	private Class<T> type;
	private List<ColumnReader> readers;
	
	public ListResultReader(Class<T> type, List<ColumnReader> readers)
	{
		this.type = type;
		this.readers = readers;
	}

	public T build(ResultSet rs) throws Exception
	{
		List<Object> list = new ArrayList<Object>();
		for (int i = 0; i < readers.size(); i++)
		{
			list.add(readers.get(i).read(rs, i + 1));
		}
		
		return type.cast(rs);
	}
}
